package com.xiaoKe.zhonghzu.ui.data;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.xiaoKe.zhonghzu.R;
import com.xiaoKe.zhonghzu.databinding.ItemEnvListBinding;
import com.xiaoKe.zhonghzu.global.bean.GeneralData;
import com.xiaoKe.zhonghzu.global.tool.ResourceTool;
import com.xiaoKe.zhonghzu.ui.onClick.OnClickListenerPositionInt;
import org.jetbrains.annotations.NotNull;
import java.util.List;

/**
 * @ProjectName : xiaoke-pad-zhongzhu
 * @Author : Shijingna
 * @Time : 2024/9/4 15:38
 * @Description : 文件描述
 */
public class EnvListAdapter extends RecyclerView.Adapter<EnvListAdapter.ViewHolder> {
    List<GeneralData> list;
    int isPosition = 0;
    public EnvListAdapter(List<GeneralData> list) {
        this.list = list;
    }

    @NonNull
    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        ItemEnvListBinding binding = ItemEnvListBinding.inflate(inflater, parent, false);
        return new ViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
        holder.binding.title.setText(list.get(position).getK().toString());
        holder.binding.lineBg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                isPosition = position;
                notifyDataSetChanged();
                onClickListenerPositionInt.onItemClick(position);
            }
        });
        holder.binding.tvBg.setVisibility(isPosition==position?View.VISIBLE:View.GONE);
        holder.binding.title.setTextColor(position==isPosition? ResourceTool.resColor(R.color.color333) :ResourceTool.resColor(R.color.color999));
    }

    @Override
    public int getItemCount() {
        return  list.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder {
        final ItemEnvListBinding binding;
        ViewHolder(ItemEnvListBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
    public OnClickListenerPositionInt onClickListenerPositionInt;

    public void setOnClickListenerPositionInt(OnClickListenerPositionInt onClickListenerPositionInt) {
        this.onClickListenerPositionInt = onClickListenerPositionInt;
    }
}
